package com.hf.eagle.web.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.filter.OncePerRequestFilter;

import com.hf.eagle.domain.UserInfo;
import com.hf.eagle.web.base.Keys;

/**
 * @author Xu,XiaoYuan
 * @version 2012.6.10 22:45
 */
public class TimeOutFilter extends OncePerRequestFilter {

	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		UserInfo userInfo = (UserInfo) session.getAttribute(Keys.ADMIN_USER);
		if (null == userInfo) {
			String contextPath = request.getContextPath();
			if (contextPath.endsWith("/")) {
				contextPath = contextPath.substring(0, contextPath.length() - 1);
			}
			response.sendRedirect(contextPath + "/timeout.jsp");
			return;
		}
		chain.doFilter(request, response);
	}

}
